<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>事件监听</button>
    <script>
        var btn = document.querySelector('button')

        btn.addEventListener('click', f2)
        function f2() {
            alert('我点击了这个按钮')
            btn.removeEventListener('click', f2)
        }


        document.addEventListener('keypress', function (e) {
            if (e.keyCode == 65) {
                alert('你按下了A键')
            }
        })
    </script>
</body>

</html>